package com.cw.base.jeeyc.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.base.jeeyc.biz.converter.ApiDatabaseConverter;
import com.cw.base.jeeyc.biz.converter.DeployDictConverter;
import com.cw.base.jeeyc.biz.intf.DeployDictQueryBiz;
import com.cw.base.jeeyc.dao.mapper.DeployDictMapper;
import com.cw.base.jeeyc.dao.model.DeployDictDo;
import com.cw.base.jeeyc.deploy.dto.DeployDictDto;

/**
 * 数据字典接口业务实现类
 *
 * @author chenw
 * @date 2019-08-26 21:21:57
 */
@Service
public class DeployDictQueryBizImpl extends ServiceImpl<DeployDictMapper, DeployDictDo> implements DeployDictQueryBiz {
    @Autowired
    private DeployDictMapper deployDictMapper;

    /**
     * 分页查询数据字典
     *
     * @param request 条件
     * @return PageInfo<DeployDictDto>
     */
    @Override
    public Page<DeployDictDto> selectPage(DeployDictDto request) {
        Page page = getBaseMapper().selectPage(new Page<>(request.getPageNum(), request.getPageSize()),
            DeployDictConverter.buildWrapper(request));
        page.setRecords(ApiDatabaseConverter.doList2DtoList(page.getRecords()));
        return page;
    }

    /**
     * 查询数据字典详情信息
     *
     * @param request 条件
     * @return DeployDictDto
     */
    @Override
    public DeployDictDto queryDetail(DeployDictDto request) {
        if (request == null) {
            return null;
        }
        return DeployDictConverter.do2Dto(deployDictMapper.selectById(request.getDictKey()));
    }

    /**
     * 根据条件查询数据字典
     *
     * @param request 条件
     * @return List<DeployDictDto>
     */
    @Override
    public List<DeployDictDto> queryList(DeployDictDto request) {
        if (request == null) {
            return null;
        }
        return DeployDictConverter.doList2DtoList(
            deployDictMapper.selectList(DeployDictConverter.buildWrapper(request)));
    }

    /**
     * 根据key查询数据字典
     *
     * @param dictKey
     * @return
     */
    @Override
    public DeployDictDto selectByKey(String dictKey) {

        return DeployDictConverter.do2Dto(deployDictMapper.selectById(dictKey));
    }
}
